use std::collections::HashMap;
use log::error;
use reqwest::{Client, Error, Response};
use serde_json::Value;

fn get_client() -> Result<Client, String> {
    match Client::builder().build() {
        Ok(client) => {
            Ok(client)
        }
        Err(err) => {
            error!("构建Client失败！Error：{}", err);
            Err(String::new())
        }
    }
}

pub async fn get(url: &str, params: Value) -> Result<Response, String>{
    let client = match get_client() {
        Ok(client) => client,
        Err(_) => {
            return Err(String::new());
        }
    };
    match client.get(url).query(&params).send().await {
        Ok(response) => {
            Ok(response)
        }
        Err(err) => {
            error!("请求失败！Error：{}", err);
            Err(String::new())
        }
    }

}